/**
 * CcException.java
 * 
 * Copyright (c) 2011 Daniel Berenguer <dberenguer@usapiens.com>
 *  
 * This file is part of the panStamp project.
 *  
 * panStamp  is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * panLoader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with panLoader; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 * USA
 * 
 * Author: Daniel Berenguer
 * Creation date: 04/01/2011
 */
package ccexception;

import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JOptionPane;

/**
 * Class: SwapException
 * 
 * Description:
 * 
 * SWAP exception class
 */
public class CcException extends Exception
{
  /**
   * Error description
   */
  private String description;

  /**
   * CcException
   *
   * Class constructor
   */
  public CcException(String message)
  {
    super(message);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    this.printStackTrace(pw);

    description = message + "\n" + sw.toString();
  }

  /**
   * print
   *
   * Print description
   */
  public void print()
  {
    System.out.println("Exception: " + description);
    if (this.getCause() != null)
      System.out.println("Origin: " + this.getCause().toString());
  }

  /**
   * display
   *
   * Display exception on popup window
   */
  public void display()
  {
    JOptionPane.showMessageDialog(null,  description, "Exception", JOptionPane.WARNING_MESSAGE);
  }
}
